/* ------------------------- htmlparser/node.js ---------------------------- */
'use strict';
(function() {
   VED.htmlParser.node = new Class({

      // initialize: function() {},

      remove: function() {
         var children = this.parent.children,
            index = VED.tools.indexOf( children, this ),
            previous = this.previous,
            next = this.next;

         previous && ( previous.next = next );
         next && ( next.previous = previous );
         children.splice( index, 1 );
         this.parent = null;
      },

      replaceWith: function( node ) {
         var children = this.parent.children,
            index = VED.tools.indexOf( children, this ),
            previous = node.previous = this.previous,
            next = node.next = this.next;

         previous && ( previous.next = node );
         next && ( next.previous = node );

         children[ index ] = node;

         node.parent = this.parent;
         this.parent = null;
      },

      insertAfter: function( node ) {
         var children = node.parent.children,
            index = VED.tools.indexOf( children, node ),
            next = node.next;

         children.splice( index + 1, 0, this );

         this.next = node.next;
         this.previous = node;
         node.next = this;
         next && ( next.previous = this );

         this.parent = node.parent;
      },

      insertBefore: function( node ) {
         var children = node.parent.children,
            index = VED.tools.indexOf( children, node );

         children.splice( index, 0, this );

         this.next = node;
         this.previous = node.previous;
         node.previous && ( node.previous.next = this );
         node.previous = this;

         this.parent = node.parent;
      }
   });
})();
